package cn.easybuy.web.backend;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSON;

import cn.easybuy.dao.ProductCategoryDao;
import cn.easybuy.dao.impl.ProductCategoryDaoImpl;
import cn.easybuy.entity.ProductCategory;
import cn.easybuy.util.Page;

public class FenleiServlet extends HttpServlet{

	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		ProductCategoryDao pcd=new ProductCategoryDaoImpl();
		int totalCount=pcd.totalCount();
		String currNo=request.getParameter("currNo");
		if (currNo==null || currNo=="") {
			currNo="1";
		}
		Page page=new Page();
		page.setCurrentPageNumber(Integer.parseInt(currNo));
		page.setPageSize(10);
		page.setTotalCount(totalCount);
		List<ProductCategory> proListAll=pcd.getProductCategoriesAll(page.getCurrentPageNumber(),page.getPageSize());
		page.setPcList(proListAll);
		String json=JSON.toJSONString(page);
		PrintWriter out=response.getWriter();
		out.print(json);
		out.flush();
		out.close();
		
		
	}

}
